package com.accenture.jproxy;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.RecursiveAction;
import java.util.function.IntFunction;
import java.util.function.IntUnaryOperator;
import java.util.stream.IntStream;

class MissException extends Exception {
}

class RangeException extends Exception {
}

class Candidate {
	String name;
	int age;

	Candidate(String name, int age) throws Exception {
		if (name == null) {
			throw new MissException();
		} else if (age < 10) {
			throw new RangeException();
		} else {
			this.name = name;
			this.age = age;
		}
	}

	public String toString() {
		return name + "age :" + age;
	}
}

//public class TestRunner {
//	public static void main(String[] args) throws Exception {
//		Candidate c;
//
//			c = new Candidate("James",20);
//			dvd d = new dvd(1,2);
//			System.out.print(d.r);
//
//
//	}
//}

class cd {
	int r;

	cd(int r) {
		this.r = r;
	}
}

class dvd extends cd {
	int c;

	dvd(int r, int c) {
		super(1);
		super.r = r;
		this.c = c;
		Inter inter = new Inter() {

			@Override
			public String getResult() {

				return null;
			}

		};

	}
}

interface Inter {
	String getResult();
}

class Bird {
	public void fly() {
		System.out.println("fly");
	}
}

class Penguin extends Bird {
	public void fly() {
		System.out.println("no fly");
	}
}

public class TestRunner {
	public static void main(String[] args) {
		List<Integer> intList = new ArrayList<>();
		intList.add(1);
		intList.add(2);
		intList.add(3);

//		intList.stream().map(n -> n).peek(System.out::print).count();
//		intList.forEach(x -> System.out.println(x + 1));

		IntStream steam = IntStream.of(1, 2, 3);
//		IntFunction<Integer> inFu  = x -> y -> x*y;
//		IntFunction<UnaryOperator> inFu  = x -> y -> x*y;
		IntFunction<IntUnaryOperator> inFu = x -> y -> x * y;
//		BiFunction<IntUnaryOperator> inFu = x -> y -> x*y;
		IntStream newSteam = steam.map(inFu.apply(10));
//		newSteam.forEach(System.out::print);


//		Stream<List<String>> iStr= Stream.of (
//				Arrays.asList ("1", "John"),
//				Arrays.asList ("2", null));
//				Stream<String> nInSt = iStr.
		

						
//		fly(()->new Bird());
//		fly(Penguin :: new);
//		
//		ForkJoinPool fjPool = new ForkJoinPool();
//
//		int data[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
//
//		fjPool.invoke(new Sum(data, 0, data.length));
		
		Path p1 = Paths.get("Pics1/Pics2/Pics3/MyPic.jpeg");
		System.out.println (p1.getNameCount());
		System.out.println (p1.getName(1));
		System.out.println (p1.getFileName());
	}
//
//	static void fly(Supplier<Bird> bird) { bird.get().fly();}

}
//
//abstract class aaa{
//	protected void a();
//}
//class bbb extends aaa{
//	public final void a() {
//		
//	}
//}

//class Content {
//	int num;
//	String str;
//	
//	@Override
//	public boolean equal(Object t) {
//		return this.num == (Content)t.num;
//	}
//}

class Sum extends RecursiveAction {
	static final int THRESHOLD_SIZE = 3;
	int stIndex, lstIndex = 0;
	int[] data;

	public Sum(int[] data, int start, int end) {
		this.data = data;
		this.stIndex = start;
		this.lstIndex = end;
	}

	protected void compute() {
		int sum = 0;
		if ((lstIndex - stIndex) <= THRESHOLD_SIZE) {
			for (int i = stIndex; i < lstIndex; i++) {
				sum += data[i];
			}
			System.out.println(sum);
		} else {
			new Sum(data, stIndex + THRESHOLD_SIZE, lstIndex).fork();
			new Sum(data, stIndex, Math.min(lstIndex, stIndex + THRESHOLD_SIZE)).compute();

//Sum a = new Sum (data, stIndex + THRESHOLD_SIZE, lstIndex);
//a.fork();
//Sum b = new Sum (data, stIndex + THRESHOLD_SIZE, lstIndex);
//b.fork();
//return a.join()+b.join();
		}
	}
}
